<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">


	#{uiConverters.layer.setItemList(buildingPermitHelper.buildingLayers)}

	<strong>#{messages['permit.data']}</strong>
	<rich:separator lineType="solid" />
	<br />
	<h:panelGrid width="80%" columns="2"
		columnClasses="introCol1,introCol2">
		<h:outputText value="#{messages['permit.partyid']}" />
		<h:panelGroup>
			<h:panelGroup id="identGroup">
				<h:inputText value="#{buildingPermitHelper.partyNationalIdentity}"
					style="width:70%" readonly="true">
				</h:inputText>
				<h:inputHidden id="partyId"
					label="#{messages['permit.partyid']}"
					value="#{buildingPermitHelper.partyNationalIdentity}"
					required="true" />
			</h:panelGroup>
			#{'   '}
			<a4j:commandLink ajaxSingle="true"
				oncomplete="#{rich:component('selectPartyPanel')}.show()">
				<f:setPropertyActionListener
					target="#{personHelper.returnValueField}"
					value="buildingPermitHelper.party" />
				<f:setPropertyActionListener
					target="#{personHelper.reRenderComponents}"
					value="identGroup, partyGroup" />
				<f:setPropertyActionListener
					target="#{legalPersonHelper.returnValueField}"
					value="buildingPermitHelper.party" />
				<f:setPropertyActionListener
					target="#{legalPersonHelper.reRenderComponents}"
					value="identGroup, partyGroup" />
				<h:outputText value="#{messages['intro.search']}" />
			</a4j:commandLink>
			<br />
			<rich:message style="color:Red;" for="partyId" />
		</h:panelGroup>

		<h:outputText value="#{messages['permit.party_full_name']}" />
		<h:panelGroup id="partyGroup">
			<a4j:region renderRegionOnly="true">
				<h:inputText id="partyName"
					value="#{buildingPermitHelper.partyName}" readonly="true"
					style="width:100%;">
				</h:inputText>
			</a4j:region>
		</h:panelGroup>

		<h:outputText value="#{messages['permit.type']}" />
		<h:panelGroup>
			<h:selectOneMenu id="buildingPermitType"
				label="#{messages['permit.type']}"
				value="#{buildingPermitHelper.permit.type}"
				converter="#{uiConverters.buildingPermitType}" required="true">
				<f:selectItems value="#{uiConverters.buildingPermitType.valueList}" />
			</h:selectOneMenu>
			<br />
			<rich:message style="color:Red;" for="buildingPermitType" />
		</h:panelGroup>

		<h:outputText value="#{messages['permit.validity_from']}" />
		<h:panelGroup>
			<rich:calendar id="validityFrom" label="#{messages['permit.validity_from']}"
				value="#{buildingPermitHelper.permit.validityFrom}" required="true" />
			<br />
			<rich:message style="color:Red;" for="validityFrom" />
		</h:panelGroup>

		<h:outputText value="#{messages['permit.validity_to']}" />
		<rich:calendar value="#{buildingPermitHelper.permit.validityTo}" />

		<h:outputText
			value="#{messages['building_permit.new_buildings_parcel']}" />
		<h:panelGroup>
			<h:panelGroup id="selectedParcelGrp">
				<h:inputText id="selectedParcel"
					value="#{buildingPermitHelper.selectedZoneName != null ? buildingPermitHelper.selectedZoneName : messages['building_permit.new_buildings_parcel_select']}"
					style="width:70%" readonly="true">
				</h:inputText>
				<h:inputHidden id="selectedZoneName"
					label="#{messages['building_permit.new_buildings_parcel']}"
					value="#{buildingPermitHelper.selectedZoneName}" required="true" />
			</h:panelGroup>
			#{'   '}
			<a4j:commandLink ajaxSingle="true"
				oncomplete="#{rich:component('selectZonePanel')}.show();">
				<h:outputText value="#{messages['intro.search']}" />
			</a4j:commandLink>
			<br />
			<rich:message style="color:Red;" for="selectedZoneName" />
		</h:panelGroup>

		<h:outputText value="#{messages['building_permit.new_buildings_layer']}" />
		<h:panelGroup>
			<h:selectOneMenu id="layerSelect"
				label="#{messages['building_permit.new_buildings_layer']}"
				value="#{buildingPermitHelper.permit.buildingUnit.level}"
				converter="#{uiConverters.layer}" required="true">
				<f:selectItems value="#{uiConverters.layer.selectItems}" />
			</h:selectOneMenu>
			<br />
			<rich:message style="color:Red;" for="layerSelect" />
		</h:panelGroup>

		<h:outputText value="#{messages['permit.request_text']}" />
		<h:panelGroup>
			<a4j:region renderRegionOnly="true">
				<h:inputTextarea id="requestText"
					label="#{messages['permit.request_text']}"
					value="#{buildingPermitHelper.permit.requestText}" required="true"
					rows="5" style="width:100%" validatorMessage="Valor muy corto">
					<f:validateLength minimum="3" />
					<a4j:support event="onblur" />
				</h:inputTextarea>
				<br />
				<rich:message style="color:Red;" for="requestText" />
			</a4j:region>
		</h:panelGroup>
	</h:panelGrid>

	<br />
	<br />

	<strong>Datos de la construccion</strong>
	<rich:separator lineType="solid" />
	<br />
	<h:panelGrid width="80%" columns="2"
		columnClasses="introCol1,introCol2">
		<h:outputText value="#{messages['building_permit.building_type']}" />
		<h:panelGroup id="buildingTypeGrp">
			<h:inputText id="buildingType"
				value="#{buildingPermitHelper.permit.buildingUnit.buildingType != null ? buildingPermitHelper.permit.buildingUnit.buildingType.name : ''}"
				style="width:70%" readonly="true">
			</h:inputText>
			#{'   '}
			<a4j:commandLink ajaxSingle="true"
				oncomplete="#{rich:component('selectBuildingTypePanel')}.show()">
				<f:setPropertyActionListener
					target="#{buildingTypeHelper.returnValueField}"
					value="buildingPermitHelper.permit.buildingUnit.buildingType" />
				<f:setPropertyActionListener
					target="#{buildingTypeHelper.reRenderComponents}"
					value="buildingType" />
				<h:outputText value="#{messages['intro.search']}" />
			</a4j:commandLink>
			<br />
			<rich:message style="color:Red;" for="buildingType" />
		</h:panelGroup>

		<h:outputText value="#{messages['building_permit.building_material']}" />
		<h:panelGroup id="buildingMaterialGrp">
			<a4j:commandLink ajaxSingle="true"
				oncomplete="#{rich:component('selectBuildingMaterialPanel')}.show()">
				<f:setPropertyActionListener
					target="#{buildingMaterialHelper.addingToList}" value="#{true}" />
				<f:setPropertyActionListener
					target="#{buildingMaterialHelper.addToListMethod}"
					value="buildingPermitHelper.addBuildingMaterial" />
				<f:setPropertyActionListener
					target="#{buildingMaterialHelper.returnValueField}"
					value="buildingPermitHelper.selectedBuildingMaterial" />
				<f:setPropertyActionListener
					target="#{buildingMaterialHelper.reRenderComponents}"
					value="buildingMaterials" />
				<h:outputText value="#{messages['intro.search']}" />
			</a4j:commandLink>
			<br />
			<br />
			<h:panelGroup id="buildingMaterials">
				<h:panelGroup
					rendered="#{not empty buildingPermitHelper.permit.buildingUnit.buildingMaterials}">
					<rich:dataGrid var="material"
						value="#{buildingPermitHelper.permit.buildingUnit.buildingMaterials}"
						columns="2">
						<table style="width: 200px">
							<tr>
								<td style="width: 70%"><h:outputText
										value="#{material.name}" /></td>
								<td><a4j:commandLink ajaxSingle="true" value="Eliminar"
										action="#{buildingPermitHelper.deleteBuildingMaterial(material)}"
										reRender="buildingMaterials">
									</a4j:commandLink></td>
							</tr>
						</table>
					</rich:dataGrid>
				</h:panelGroup>
				<h:panelGroup
					rendered="#{empty buildingPermitHelper.permit.buildingUnit.buildingMaterials}">
					Especifique uno o mas materiales de construccion
				</h:panelGroup>
			</h:panelGroup>
		</h:panelGroup>

		<h:outputText value="#{messages['building_permit.building_area']}" />
		<h:panelGroup>
			<h:inputText id="builtArea"
				label="#{messages['building_permit.building_area']}"
				value="#{buildingPermitHelper.permit.buildingUnit.builtArea}"
				required="true" />
			<br />
			<rich:message style="color:Red;" for="builtArea" />
		</h:panelGroup>

		<h:outputText value="#{messages['building_permit.number_of_floors']}" />
		<h:panelGroup>
			<rich:inputNumberSpinner id="numberOfFloors"
				label="#{messages['building_permit.number_of_floors']}"
				value="#{buildingPermitHelper.permit.buildingUnit.numberOfFloors}"
				minValue="1" maxValue="100" required="true" />
			<br />
			<rich:message style="color:Red;" for="numberOfFloors" />
		</h:panelGroup>

		<h:outputText value="#{messages['building_permit.building_value']}" />
		<h:panelGroup>
			<h:inputText id="buildingUnitValue"
				label="#{messages['building_permit.building_value']}"
				value="#{buildingPermitHelper.permit.buildingUnit.value}"
				required="true" />
			<br />
			<rich:message style="color:Red;" for="buildingUnitValue" />
		</h:panelGroup>
	</h:panelGrid>

	<br />
	<br />

	<strong>#{messages['txt.land_uses']}</strong>
	<rich:separator lineType="solid" />
	<br />
	<h:panelGrid width="80%" columns="2"
		columnClasses="introCol1,introCol2">
		<h:outputText value="#{messages['txt.land_use']}" />
		<h:panelGroup>
			<h:panelGroup id="grpLandUse">
				<h:inputText readonly="true" style="width:60%"
					value="#{buildingPermitHelper.selectedLandUseName}" />
				<h:inputHidden id="txtLandUse" label="#{messages['txt.land_use']}"
					value="#{buildingPermitHelper.selectedLandUseName}" required="true" />
			</h:panelGroup>

			<a4j:commandLink ajaxSingle="true"
				oncomplete="#{rich:component('selectLandUsePanel')}.show()">
				<f:setPropertyActionListener
					target="#{selectLandUseHelper.returnValueField}"
					value="buildingPermitHelper.permit.buildingUnit.landUse" />
				<f:setPropertyActionListener
					target="#{selectLandUseHelper.reRenderComponents}"
					value="grpLandUse" />
				<h:outputText value="#{messages['intro.search']}" />
			</a4j:commandLink>
			<br />
			<rich:message style="color:Red;" for="txtLandUse" />
		</h:panelGroup>

		<h:outputText value="#{messages['txt.other_land_uses']}" />
		<h:panelGroup id="otherLandUsesGrp">
			<a4j:commandLink ajaxSingle="true"
				oncomplete="#{rich:component('selectLandUsePanel')}.show()">
				<f:setPropertyActionListener
					target="#{selectLandUseHelper.addingToList}" value="#{true}" />
				<f:setPropertyActionListener
					target="#{selectLandUseHelper.addToListMethod}"
					value="buildingPermitHelper.addLandUse" />
				<f:setPropertyActionListener
					target="#{selectLandUseHelper.returnValueField}"
					value="buildingPermitHelper.selectedLandUse" />
				<f:setPropertyActionListener
					target="#{selectLandUseHelper.reRenderComponents}"
					value="otherLandUses" />
				<h:outputText value="#{messages['intro.search']}" />
			</a4j:commandLink>
			<br />
			<br />
			<h:panelGroup id="otherLandUses">
				<h:panelGroup
					rendered="#{not empty buildingPermitHelper.permit.buildingUnit.otherLandUses}">
					<rich:dataGrid var="landUse"
						value="#{buildingPermitHelper.permit.buildingUnit.otherLandUses}"
						columns="2">
						<table style="width: 200px">
							<tr>
								<td style="width: 70%"><h:outputText
										value="#{selectLandUseHelper.landUseName(landUse)}" /></td>
								<td><a4j:commandLink ajaxSingle="true" value="Eliminar"
										action="#{buildingPermitHelper.deleteLandUse(landUse)}"
										reRender="otherLandUses">
									</a4j:commandLink></td>
							</tr>
						</table>
					</rich:dataGrid>
				</h:panelGroup>
				<h:panelGroup
					rendered="#{empty buildingPermitHelper.permit.buildingUnit.otherLandUses}">
					#{messages['txt.land_uses_select']}
				</h:panelGroup>
			</h:panelGroup>
		</h:panelGroup>

	</h:panelGrid>


</ui:composition>
